<?php 
namespace PsiFramework\Classes\Util\Parameters\DAO;

/**
 * PsiFramework
 * Php Simple Framework
 *
 * @author Rémi San
 * @version beta
 */

/**
 * The ServiceMappingDAO class is the class to retrieve
 * service mapping parameters
 *
 * @package Util.Parameters.DAO
 */
class ServiceMappingDAO
{

    protected /*DomElement*/ $_services ;

    public function __construct()
    {
        $this->_services = null ;
    }

    public function init(\DomElement $services)
    {
        $this->_services = $services ;
    }

    public function initByFile(/*string*/ $services)
    {
        $document = new \DomDocument();
        $document->load($file);
        $this->_services = $document->documentElement ;
        return $this->_services->getAttribute("application");
    }

    public function readServiceMapping()
    {
        $servicesArray = $this->_services->getElementsByTagName("service");

        $serviceMappings = array();

        foreach ($servicesArray as $service) {
            $serviceName = $service->getAttribute("name");
            $serviceClass = $service->getAttribute("class");

            $serviceMappings[$serviceName] = $serviceClass ;
        }

        return $serviceMappings ;
    }

}
